<template>
	<el-card style="height:100% ;">
		<div v-if="student">
		  <el-select  v-model="tbClassId" placeholder="请选择班级" @change="change" clearable>
		    <el-option v-for="bj in bjs" :key="bj.id" :value="bj.id" :label="bj.name"></el-option>
		  </el-select>
		</div>
	<div style="height:100%;">
	    <el-scrollbar style="height:100%">   
			    <el-table
				v-if="tbClassId"
			      :data="tableData"
			      style="width: 100%"
			      :row-class-name="tableRowClassName">
				<el-table-column prop="student.className" label="班级" clearable>
				</el-table-column>
				 <el-table-column  prop="student.name" label="姓名" clearable>
				 </el-table-column>
			      <el-table-column  prop="course.name" label="科目" clearable>
			      </el-table-column>
			      <el-table-column prop="shijuan.name"  label="试卷名称" clearable>
			      </el-table-column>
			      <el-table-column prop="grade"label="成绩" clearable>
			      </el-table-column>
				  <el-table-column  label="判定结果" clearable>
					    <template slot-scope="scope">
					<el-tag :type="(scope.row.grade>scope.row.shijuan.jige)?'success':'danger'" v-text="(scope.row.grade>scope.row.shijuan.jige)?'合格':'不合格'"></el-tag>
					</template>
				  </el-table-column>
			    </el-table>
		 
	    </el-scrollbar>
	  </div>
	   </el-card>
</template>

<script>
	  export default {
		  created() {
		  	this.getList()
			this.getpage()
		  },
	    methods: {
			change(){
				console.log(123);
				this.$ajax.post('/Grade/findByclass',{"classid":this.tbClassId}).then(res=>{
					this.tableData=res.data.data
					console.log(this.tableData);
				})
			},
	      tableRowClassName({row, rowIndex}) {
	        if (rowIndex === 1) {
	          return 'warning-row';
	        } else if (rowIndex === 3) {
	          return 'success-row';
	        }
	        return '';
	      },
		  
		 getList(){
		   	this.$ajax.post('/Grade/list',{}).then(res=>{
		   	  var result=res.data;
		   	  this.tableData=result.data;
			  var roles=window.sessionStorage.getItem("roles")
				if(roles=="ROLE_STUDENT"){
					this.student=false
					this.tbClassId=true
					var id=window.sessionStorage.getItem("id")
					var ddd=new Array;
					for (let i = 0; i < this.tableData.length; i++) {	
						if(id==this.tableData[i].student.id){
							ddd.push(this.tableData[i])
						}
					}
					console.log(ddd);
					this.tableData=ddd
				}else{
					return
				}
		   	  console.log(this.tableData);
		   	})
		 
		 },
		  getpage(){
			this.$ajax.post('banji/list', {}).then(res => {
				var result = res.data;
				this.bjs = result.data;
      })
		  },
	    },
	    data() {
	      return {
	        tableData: [],
			hege:false,
				tbClassId: '',
				bjs: [],
				student:true
			
	      }
	    }
	  }
</script>

<style>

</style>
